package com.gy.cloud.cloudc;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.ribbon.proxy.annotation.Hystrix;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class HiService {

    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "hiError")
    public String hi(String name) {
        System.out.println(name);
        String hi = restTemplate.getForObject("http://SERVICE-B/hi?name=" + name, String.class);
        System.out.println(hi);
        return hi;
    }

    public String hiError(String name) {
        return "Hi, " + name +", Sorry Error !";
    }

}
